package com.assignwork.service.impl;

import com.assignwork.dto.FixedMachineSearchDTO;
import com.assignwork.dto.FixedMachineSubmitDTO;
import com.assignwork.entity.FixedMachine;
import com.assignwork.mapper.FixedMachineMapper;
import com.assignwork.service.IFixedMachineService;
import com.assignwork.vo.FixedMachineListVO;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springblade.core.mp.base.BaseServiceImpl;
import org.springblade.core.tool.utils.BeanUtil;
import org.springblade.system.cache.DictBizCache;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @ClassName FixedMachineServiceImpl
 * @Description 固机接口实现
 * @Author dujianyu
 * @Date 2023/12/13 16:13
 */
@Service
public class FixedMachineServiceImpl extends BaseServiceImpl<FixedMachineMapper, FixedMachine> implements IFixedMachineService {

    @Override
    public IPage<FixedMachineListVO> selectFixedMachinePage(FixedMachineSearchDTO dto, IPage<FixedMachineListVO> page) {
        List<FixedMachineListVO> data = baseMapper.selectFixedMachineList(dto, page);
        return page.setRecords(dataProcess(data));
    }

    @Override
    public List<FixedMachineListVO> selectFixedMachineList(FixedMachineSearchDTO dto) {
        List<FixedMachineListVO> data = baseMapper.selectFixedMachineList(dto, null);
        return dataProcess(data);
    }

    @Override
    public boolean submitFixedMachine(FixedMachineSubmitDTO dto) {
        FixedMachine entity = BeanUtil.copy(dto, FixedMachine.class);
        return super.saveOrUpdate(entity);
    }

    private List<FixedMachineListVO> dataProcess(List<FixedMachineListVO> data) {
        for (FixedMachineListVO item : data) {
            item.setBerthName(DictBizCache.getValue("fixed_machine_berth", item.getBerth()));
            item.setCodeName(DictBizCache.getValue("machine_kind", item.getCode()));
        }
        return data;
    }

}
